<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>按钮周围光效</title>
  </head>
  <body>
    <div class="btns">
      <div class="btn">test</div>
    </div>
    <div class="btns2">
      <div class="btn">test</div>
    </div>
  </body>
  <style>
    /* :root { */
    /* } */
    .btns2 {
      --btn-width: 200px;
      --btn-height: 40px;
      --btn-radius: 10px;
      display: flex;
      justify-content: center;
      align-items: center;
      position: relative;
      width: var(--btn-width);
      height: var(--btn-height);
      margin-top: 20px;
      border-radius: var(--btn-radius);
      background-image: linear-gradient(
        90deg,
        #03a9f4,
        #f441a5,
        #ffeb3b,
        #03a9f4
      );
      background-size: 400%, 100%;
      /* background-position-x: 0%; */
    }
    .btns2::before {
      content: '';
      display: block;
      position: absolute;
      width: 100%;
      height: 100%;
      background-image: linear-gradient(
        90deg,
        #03a9f4,
        #f441a5,
        #ffeb3b,
        #03a9f4
      );
      border-radius: var(--btn-radius);
      background-size: 400% 100%;
    }
    .btns2 .btn {
      color: #fff;
      font-size: 20px;
      z-index: 1;
    }
    .btns2:hover {
      animation: backgroundPositionRound 4s linear infinite;
    }
    .btns2:hover::before {
      filter: blur(10px);
      animation: backgroundPositionRound 4s linear infinite;
    }
    @keyframes backgroundPositionRound {
      0% {
        background-position-x: 0;
      }
      100% {
        background-position-x: 400%;
      }
    }
  </style>
  <style>
    .btns {
      --btn1-width: 100px;
      --btn1-height: 70px;
      --btn1-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
      width: var(--btn1-width);
      height: var(--btn1-height);
      margin-top: 10px;
      border-radius: var(--btn1-radius);
      overflow: hidden;
      background-color: #000;
    }
    .btns::before {
      content: '';
      width: 120%;
      height: 70%;
      position: absolute;
      background-image: linear-gradient(90deg, #376be3, #eb4c70);
      animation: doCircle 4s linear infinite;
    }
    .btns::after {
      content: '';
      position: absolute;
      inset: 3px;
      border-radius: var(--btn1-radius);
      background-color: #000;
    }
    .btns .btn {
      color: #fff;
      font-size: 24px;
      z-index: 1;
    }
    @keyframes doCircle {
      0% {
        transform: rotate(0deg);
      }
      100% {
        transform: rotate(360deg);
      }
    }
  </style>
</html>
